package com.sinosoft.dsp.component.bpm.handler;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jbpm.api.model.OpenExecution;
import org.jbpm.api.task.Assignable;
import org.jbpm.api.task.AssignmentHandler;

import com.sinosoft.dsp.func.entity.setting.system.user.SinoSysUser;
import com.sinosoft.dsp.func.service.setting.system.role.RoleService;
import com.sinosoft.dsp.platform.utils.SinoManagedBean;

public class SinoAssignmentHandler implements AssignmentHandler {

	private static final long serialVersionUID = -7263465362016813396L;

	// 分配策略
	String strategy;

	// 参与者的角色和类型
	Map<String, String> roleIdAndTypes;

	@Override
	public void assign(Assignable assignable, OpenExecution execution)
			throws Exception {
		RoleService roleService = SinoManagedBean.findBean("roleService");
		Map<String, String> userIds = new HashMap<String, String>();
		if (roleIdAndTypes != null) {
			for (String roleId : roleIdAndTypes.keySet()) {
				List<SinoSysUser> users = roleService
						.findRoleUserListByRoleUUID(roleId);
				for (SinoSysUser u : users) {
					userIds.put(u.getUseruuid(), null);
				}
			}
		}

		if (userIds.size() > 0) {
			for (String userId : userIds.keySet()) {
				assignable.addCandidateUser(userId);
			}
		}
		// TODO
	}

}
